<%@ page import="java.sql.*" contentType="text/html;charset=windows-1252"%>
<%
 String name,subject,author;
 int cat_id;
 name=request.getParameter("NAME");
 subject=request.getParameter("SUBJECT");
 author=request.getParameter("AUTHOR");
 cat_id=Integer.parseInt(request.getParameter("CATEGORY"),10);

 //making connection
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   String url = "jdbc:odbc:iranhk";
   Connection con = DriverManager.getConnection(url, "iranhk", "iranhk");

 //get result of search 
 String st;
 PreparedStatement pst;
 if (cat_id==0){ //category='ALL ARTICLES' dont use categorykey for search
  st=
   "select tb_tools.id,tb_tools.name,tb_tools.subject,tb_tools.dat,tb_members.id authorid,tb_members.name author "+
      "from tb_tools,tb_members " +      
      "where "+
         "(tb_tools.fk_author_id=tb_members.id) and "+
         "(tb_tools.name like ?) and "+
         "(tb_tools.subject like ?) and "+
         "(tb_members.name like ?) "+
     "order by tb_tools.dat; ";
     pst=con.prepareStatement(st);
     pst.setObject(1,"%"+name+"%");
     pst.setString(2,"%"+subject+"%");
     pst.setString(3,"%"+author+"%");
 } else { //category<>'ALL ARTICLES' use category key for search
  st=
   "select tb_tools.id,tb_tools.name,tb_tools.subject,tb_tools.dat,tb_members.id authorid,tb_members.name author "+
      "from tb_tools,tb_members,tb_category "+      
      "where "+
         "(tb_tools.fk_author_id=tb_members.id) and "+
         "(tb_tools.name like ?) and "+
         "(tb_tools.subject like ?) and "+
         "(tb_members.name like ?) and "+
         "(tb_tools.fk_category_id=tb_category.id(+)) and "+         
         "(tb_category.id=?) "+
     "order by tb_tools.dat; ";
     pst=con.prepareStatement(st);
     pst.setObject(1,"%"+name+"%");
     pst.setString(2,"%"+subject+"%");
     pst.setString(3,"%"+author+"%");
     pst.setInt(4,cat_id);
  }
     ResultSet rst=pst.executeQuery();    
     session.setAttribute("resultSet",rst);
     //out.print(pst.toString());
    /* while (rst.next()){ 
      out.print(rst.getString("NAME"));
    }*/
%>

<jsp:include page="../displayer/tools.jsp" flush="true">
  <jsp:param name="" value=""/>
</jsp:include> 